<template>
<div>
    <div class="box-mid">
        <el-button v-hasPermission="'dict:add'" type="primary" @click="$emit('add')">新增</el-button>
        <el-button v-hasPermission="'dict:delete'" @click="handleDel">删除</el-button>
        <el-button v-hasPermission="'dict:export'" v-preventReClick="2000" @click="$emit('export')">导出Excel</el-button>
    </div>
    <div class="box-table">
        <el-table v-loading="tableData.loading" :data="tableData.rows" tooltip-effect="dark" @selection-change="handleSelected">
            <template slot="empty">
                <no-data :types="tableData.isSearch">
                    <span>暂无数据</span>
                </no-data>
            </template>
            <el-table-column type="selection" width="55"></el-table-column>
            <el-table-column prop="keyy" label="键" show-overflow-tooltip></el-table-column>
            <el-table-column prop="valuee" label="值" show-overflow-tooltip></el-table-column>
            <el-table-column prop="tableName" label="表名" show-overflow-tooltip></el-table-column>
            <el-table-column prop="fieldName" label="字段" show-overflow-tooltip></el-table-column>
            <el-table-column label="操作">
                <template slot-scope="scope">
                    <el-button v-hasPermission="'dict:update'" @click="$emit('add', scope.row)" type="text">修改</el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>
    <div class="box-pagenation" v-if="tableData.rows.length>0">
        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="tableData.currentPage" :page-size="tableData.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="tableData.total">
        </el-pagination>
    </div>
</div>
</template>

<script>
import NoData from '@/components/NoData'
export default {
    name: 'ProjectsTable',
    props: {
        tableData: {
            type: Object,
            required: true
        }
    },
    components: { NoData },
    data () {
        return {
            selected: []
        }
    },
    methods: {
        handleDel () {
            if (!this.selected.length) {
                this.$message.info('请选择要删除的字典')
            } else {
                this.$confirm('确定要删除该字典吗?', '提示', {
                    confirmButtonText: '确 定',
                    cancelButtonText: '取 消',
                    type: 'warning'
                }).then(() => {
                    this.handleDelConfirm()
                }).catch(() => {})
            }
        },
        handleDelConfirm () {
            this.$delete('/dict', this.selected.map(v => v.dictId).join(',')).then(res => {
                if (res) {
                    this.$message.success('删除成功')
                    this.$emit('flash')
                }
            })
        },
        handleCurrentChange (val) {
            this.tableData.currentPage = val
            this.$emit('flash')
        },
        handleSizeChange (val) {
            this.tableData.pageSize = val
            this.$emit('flash')
        },
        handleSelected (val) {
            this.selected = val
        }
    }
}
</script>
